package com.hippo.core.ui.components

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource
import com.hippo.core.R
import com.hippo.core.ui.theme.Shapes

@Composable
fun ConfirmAlertDialog(
    title: String = stringResource(R.string.hint),
    content: String,
    onConfirm: () -> Unit,
    onCancel: (() -> Unit)? = null
) {

    var showDialog by remember { mutableStateOf(true) }

    if (showDialog) {

        AlertDialog(
            shape = Shapes.medium,
            onDismissRequest = {
                showDialog = false
            },
            title = {
                Text(text = title)
            },
            text = {
                Text(text = content)
            },
            dismissButton = {
                SecondaryButton(
                    text = stringResource(id = R.string.cancel),
                    onClick = {
                        showDialog = false
                        onCancel?.invoke()
                    }
                )
            },
            confirmButton = {
                ThemeButton(
                    text = stringResource(id = R.string.sure),
                    onClick = {
                        showDialog = false
                        onConfirm()
                    }
                )
            }
        )
    }
}